﻿function msgError() {
    alert("INTERNAL ERROR: Intentelo mas tarde.");
}

function openPopup(url, title, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    window.open(url, title, "toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=no, copyhistory=no, width=" + w + ", height=" + h + ", top=" + top + ", left=" + left);
}

Date.prototype.Add = function (strInterval, intIncrement) {
    if (
        strInterval != "M"
        && strInterval != "D"
        && strInterval != "Y"
        && strInterval != "h"
        && strInterval != "m"
        && strInterval != "uM"
        && strInterval != "uD"
        && strInterval != "uY"
        && strInterval != "uh"
        && strInterval != "um"
        && strInterval != "us"
        ) {
        throw ("DateAdd: Second parameter must be M, D, Y, h, m, uM, uD, uY, uh, um or us");
    }

    if (typeof (intIncrement) != "number") {
        throw ("DateAdd: Third parameter must be a number");
    }

    switch (strInterval) {
        case "M":
            this.setMonth(parseInt(this.getMonth()) + parseInt(intIncrement));
            break;

        case "D":
            this.setDate(parseInt(this.getDate()) + parseInt(intIncrement));
            break;

        case "Y":
            this.setYear(parseInt(this.getYear()) + parseInt(intIncrement));
            break;

        case "h":
            this.setHours(parseInt(this.getHours()) + parseInt(intIncrement));
            break;

        case "m":
            this.setMinutes(parseInt(this.getMinutes()) + parseInt(intIncrement));
            break;

        case "s":
            this.setSeconds(parseInt(this.getSeconds()) + parseInt(intIncrement));
            break;

        case "uM":
            this.setUTCMonth(parseInt(this.getUTCMonth()) + parseInt(intIncrement));
            break;

        case "uD":
            this.setUTCDate(parseInt(this.getUTCDate()) + parseInt(intIncrement));
            break;

        case "uY":
            this.setUTCFullYear(parseInt(this.getUTCFullYear()) + parseInt(intIncrement));
            break;

        case "uh":
            this.setUTCHours(parseInt(this.getUTCHours()) + parseInt(intIncrement));
            break;

        case "um":
            this.setUTCMinutes(parseInt(this.getUTCMinutes()) + parseInt(intIncrement));
            break;

        case "us":
            this.setUTCSeconds(parseInt(this.getUTCSeconds()) + parseInt(intIncrement));
            break;
    }
    return this;
}

function Navigate(TabActual, TabNuevo) {
    $("ul.tabs li[id=" + TabActual + "]").removeClass("active");
    $("ul.tabs li[id=" + TabNuevo + "]").addClass("active");
    $(".tab_content").hide();
    var activeTab = $("ul.tabs li[id=" + TabNuevo + "]").find("a").attr("href");
    $(activeTab).fadeIn();
    return false;
}

Date.prototype.formatDate = function (format) {
    var date = this;
    if (!format)
        format = "MM/dd/yyyy";
    var month = date.getMonth() + 1;
    var year = date.getFullYear();
    format = format.replace("MM", month.toString().padL(2, "0"));
    if (format.indexOf("yyyy") > -1)
        format = format.replace("yyyy", year.toString());
    else if (format.indexOf("yy") > -1)
        format = format.replace("yy", year.toString().substr(2, 2));

    format = format.replace("dd", date.getDate().toString().padL(2, "0"));
    var hours = date.getHours();
    if (format.indexOf("t") > -1) {
        if (hours > 11)
            format = format.replace("t", "pm")
        else
            format = format.replace("t", "am")
    }

    if (format.indexOf("HH") > -1)
        format = format.replace("HH", hours.toString().padL(2, "0"));
    if (format.indexOf("hh") > -1) {
        if (hours > 12) hours - 12;
        if (hours == 0) hours = 12;
        format = format.replace("hh", hours.toString().padL(2, "0"));
    }
    if (format.indexOf("mm") > -1)
        format = format.replace("mm", date.getMinutes().toString().padL(2, "0"));
    if (format.indexOf("ss") > -1)
        format = format.replace("ss", date.getSeconds().toString().padL(2, "0"));
    return format;
}

String.repeat = function (chr, count) {
    var str = "";
    for (var x = 0; x < count; x++) { str += chr };
    return str;
}
String.prototype.padL = function (width, pad) {
    if (!width || width < 1)
        return this;
    if (!pad) pad = " ";
    var length = width - this.length;
    if (length < 1) return this.substr(0, width);
    return (String.repeat(pad, length) + this).substr(0, width);
}

String.prototype.padR = function (width, pad) {
    if (!width || width < 1)
        return this;
    if (!pad) pad = " ";
    var length = width - this.length;
    if (length < 1) this.substr(0, width);
    return (this + String.repeat(pad, length)).substr(0, width);
}